//
//  WYStatus.swift
//  WYWeibo
//
//  Created by wangyi on 16/7/14.
//  Copyright © 2016年 wangyi. All rights reserved.
//

import UIKit

class WYStatus: NSObject {
    
    //发布时间
    var created_at: String?
    //微博 id
    var id: Int64 = 0
    //微博内容
    var text: String?
    //微博来源
    var source: String?
    //转发数
    var reposts_count: Int = 0
    //评论数
    var comments_count: Int = 0
    //表态数(赞)
    var attitudes_count: Int = 0
    //关注的对象
    var user:WYUser?
    //配图信息
    var pic_urls: [WYStatusPictureInfos]?
    //转发微博对象
    var retweeted_status: WYStatus?
    
    init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
        
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    // 由于 user 和 上一级同步  要自己转换
    override func setValue(value: AnyObject?, var forKey key: String) {
      
        if key == "user" {
        
            guard let dic = value as? [String: AnyObject] else {
            
                return
            }
            user = WYUser(dic: dic)
        } else if key == "retweeted_status" {
            
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            
            retweeted_status = WYStatus(dic: dic)
           
        } else if key == "pic_urls" {
        
            guard let dicArray = value as? [[String: AnyObject]] else {
            
                return
            }
            
            var tempArray = [WYStatusPictureInfos]()
            for dic in dicArray {
            
                let pictureInfos = WYStatusPictureInfos(dic: dic)
                tempArray.append(pictureInfos)
            }
            pic_urls = tempArray
        }else {
        
            super.setValue(value, forKey: key)
        }
    }
    
}
